Skip to content

SONARJAVA-6710: Fix FN on empty condition loop - #5865

Open
joke1196 wants to merge 2 commits into
masterfrom
dk/USER-2406
Open

SONARJAVA-6710: Fix FN on empty condition loop#5865
joke1196 wants to merge 2 commits into
masterfrom
dk/USER-2406

Conversation

@joke1196

@joke1196 joke1196 commented Aug 3, 2026

Copy link
Copy Markdown

Part of


Summary by Gitar

  • Bug fix:
    • Fixed false negative in LoopExecutingAtMostOnceCheck for empty condition for(;;) loops by requiring conditional control flow in the body
  • Tests:
    • Added test cases covering various conditional structures and scope boundaries like lambdas and anonymous classes

This will update automatically on new commits.

@joke1196
joke1196 requested a review from rombirli August 3, 2026 11:55
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6710

Comment thread java-checks/src/test/files/checks/LoopExecutingAtMostOnceCheck.java
@gitar-bot

gitar-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Fixes a false negative in LoopExecutingAtMostOnceCheck for empty condition for loops by requiring conditional control flow in the body, and addresses the switch-expression test isolation finding.

✅ 1 resolved
Quality: Switch-expression test not isolated to the feature it verifies

📄 java-checks/src/test/files/checks/LoopExecutingAtMostOnceCheck.java:341-351
The switch-expression case at lines 342-351 also contains an if (x > 15) { break; }. Because containsConditional returns true on encountering either the switch expression or the if, this test would still be reported Compliant even if visitSwitchExpression detection regressed, so it does not actually guard switch-expression handling. Consider removing the if (leaving only the switch-expression assignment before the final break) so the test isolates the feature under test.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

sonarqube-next Bot commented Aug 3, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant